// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#pragma once

#include <cantor/unresolved/visitor.h>

namespace cantor::unresolved {

    class UnresolvedRangeVar;
    class UnresolvedColumnDef;
    class UnresolvedConstraint;
    class UnresolvedTableOption;
    class UnresolvedTableName;

    class UnresolvedCreateTableStmt : public UnresolvedVisitor<UnresolvedCreateTableStmt> {
    public:
        static constexpr const cantor::pb::ast::StmtType TYPE = cantor::pb::ast::StmtType::STMT_CREATE_TABLE;

        UnresolvedCreateTableStmt(const cantor::pb::ast::CreateTableStmt &node) :
                                                                     instance(node) {
        }

        UnresolvedCreateTableStmt(const cantor::pb::ast::Statement &node) : instance(node.create_table_stmt()) {
        }

        ~UnresolvedCreateTableStmt() override = default;

        const pb::Location& location_impl() const {
            return  instance.location();
        }

        const pb::Status &error_status_impl() const {
            return  instance.status();
        }

        bool if_not_exist() const {
            if (instance.has_if_not_exist()) {
                return instance.if_not_exist();
            }
            return false;
        }

        bool has_table_name() const {
           return  instance.has_table_name();
        }
        UnresolvedTableName table_name() const;

        bool has_ref_table_name() const {
            return  instance.has_ref_table_name();
        }

        UnresolvedTableName ref_table_name() const;

        size_t columns_size() const {
            return instance.columns_size();
        }

        UnresolvedColumnDef column(size_t i) const;

        size_t constraints_size() const {
            return instance.constraints_size();
        }

        UnresolvedConstraint constraint(size_t i) const;

        size_t table_options_size() const {
            return instance.options_size();
        }

        UnresolvedTableOption table_option(size_t i) const;

        const cantor::pb::ast::CreateTableStmt &instance;
    };
} // namespace cantor::unresolved
